<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        WebChat.renderWebChat(
          {
            directLine: WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() }),
            store: testHelpers.createStore()
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        // GIVEN: A ready-to-submit Adaptive Card with suggested actions shown below
        await pageObjects.sendMessageViaSendBox('card inputs', { waitForSend: true });
        await pageConditions.minNumActivitiesShown(2);

        await pageObjects.sendMessageViaSendBox('suggested-actions', { waitForSend: true });
        await pageConditions.suggestedActionsShown();
        await pageConditions.scrollToBottomCompleted();

        // To submit the input form, the number field is mandatory.
        document.querySelector('.ac-adaptiveCard input[type="number"]').value = '1';

        // WHEN: The Adaptive Card is being submitted.
        const submitButton = await document.querySelector('button.ac-pushButton:nth-of-type(2)');

        await submitButton.click();
        await pageConditions.minNumActivitiesShown(5);

        // THEN: It should stick to the bottom.
        await pageConditions.scrollToBottomCompleted();

        await host.snapshot('local');
      });
    </script>
  </body>
</html>
